import GameDataManager from "../../Models/GameDataManager";
import {
  IGameStartup,
  IProgressManager,
} from "../../../ADCore/Interfaces/IGameManager";
import { GameState } from "../../../ADCore/Interfaces/IEnum";
import ADQ from "../../../ADCore/Core/ADQ";
import { MusicEnums } from "../../Enums/MusicEnums";
import { StateMachine } from "../../../ADCore/Implements/ImpStateMachine/StateMachine";
import LoadingPageView from "../../../views/Dialogs/LoadingPageView";

/**
 * 游戏加载 状态机
 */
export default class GameLoadingState extends StateMachine {
  progress: IProgressManager;
  onEnter(obj?: any) {
    var self = this;
    var loading = LoadingPageView.showPage(this, this.onComplete, () => {
      var gameData = new GameDataManager();
      gameData.loadInitData(self.progress);
    });
    this.progress = loading.progress;
  }

  onComplete() {
    console.debug("播放音乐！");
    ADQ.globalSound.play(MusicEnums.backgroudMusic);
    (this.owner as IGameStartup).stateMachine.changeState(GameState.run, 1);
  }
}
